﻿using System;
using System.Collections.Generic;
using System.Web;
using ZLDC.Common.Estate;
using System.Data;

namespace ZLDC.Estate
{
    public class CHnadlerRoomNo
    {
                                        public static void ChooseMethod()
        {
            
            string act = _Request.GetString("act", "");
            switch (act)
            {                
                case "SNF":
                    SelectNameByFloor();
                    break;
                case "Update":
                    UpdateOtherNameById();                      break;
                case "del":
                    DeleteNameById();
                    break;

                case "delAll":                                  DelAll();
                    break;
                    
                case "ub":
                    UpdateBName();                              break;
                case "UR":
                    UpdateOtherName();                          break;
                case "SelectCount":
                    SelectRooms();
                    break;
                case "SelectRoomNoList":
                    SelectRoomNoList();
                    break;
                case "SelectNameByFloor":
                    SelectNameByFloor();
                    break;
                case "getHousingIDByRoomID":                          getHousingIDByRoomID();
                    break;

            }
        }
       
                                private static void SelectNameByFloor()
        {
            int bid = _Request.GetInt("bid", 0);
            string floor = _Request.GetString("floor", "");
            string json = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectNameByFloor(floor, bid);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                                private static void getHousingIDByRoomID()
        {
            int roomid = _Request.GetInt("roomid", 0);
            int tradetype = _Request.GetInt("tradetype", 0);    
            string json = ZLDC.Topo.BLL.Estate.RoomNoBLL.p_getHousingIDByRoomID(roomid, tradetype);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void DeleteNameById()
        {
            int id = _Request.GetInt("id", 0);
            int json = ZLDC.Topo.BLL.Estate.RoomNoBLL.DeleteNameById(id);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                                public static void DelAll()
        {
            int id = 0;
            int json = 0;
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("idlist"), '|');

            if (IDList != null && IDList.Length > 0)
            {
                for (int i = 0; i < IDList.Length; i++)
                {
                    id = _Convert.ToInt(IDList[i], 0); 
                    json = ZLDC.Topo.BLL.Estate.RoomNoBLL.DeleteNameById(id);
                }
            }            

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        

                public static void UpdateOtherNameById()
        {
            string id = _Request.GetString("id", "0");
            string name = _Request.GetString("name", "");
            string type = _Request.GetString("type", "0");
            string tablename = _Request.GetString("tname", "");
            string commitName = _Request.GetString("cName", "");
            string commitDept = _Request.GetString("Cdept", "");
            string commitDeptId = _Request.GetString("cDId", "0");

                        if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("直接添加别名"))
                type = "";

            int json = ZLDC.Topo.BLL.Estate.EstateBLL.UpdateOtherNameById(id, name, type, tablename, commitName, commitDept, commitDeptId);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

                public static void UpdateBName()
        {
            string[] IDList = _Utility.GetStringBySplit(_Request.GetString("idlist"), '|');             string name = _Request.GetString("name", "");
            string type = _Request.GetString("type", "0");
            string tablename = _Request.GetString("tname", "");
            string commitName = _Request.GetString("cName", "");
            string commitDept = _Request.GetString("Cdept", "");
            string commitDeptId = _Request.GetString("cDId", "0");

            string outmsg = "别名申请成功-待审核！";

                        if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("直接添加别名"))
            {
                type = "";
                outmsg = "别名添加成功！";
            }

            int json = 0;            
            for (int i = 0; i < IDList.Length; i++)
            {
                int id = _Convert.ToInt(IDList[i].ToString(), 0);
                if (id > 0)
                    json = ZLDC.Topo.BLL.Estate.BuildBLL.UpdateBName(IDList[i].ToString(), name, type, tablename, commitName, commitDept, commitDeptId);
            }

            if (json <= 0)
                outmsg = "别名申请失败！";

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(outmsg);
            HttpContext.Current.Response.End();
        }

                public static void UpdateOtherName()
        {
            string id = _Request.GetString("id", "0");
            string name = _Request.GetString("name", "");
            string type = _Request.GetString("type", "0");
            string tablename = _Request.GetString("tname", "");
            string commitName = _Request.GetString("cName", "");
            string commitDept = _Request.GetString("Cdept", "");
            string commitDeptId = _Request.GetString("cDId", "0");

                        if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("直接添加别名"))
                type = "";

            int json = ZLDC.Topo.BLL.Estate.RoomNoBLL.UpdateOtherName(id, name, type, tablename, commitName, commitDept, commitDeptId);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void SelectRooms()
        {
            string bid = _Request.GetString("bid", "0");
            string floor = _Request.GetString("floor", "0");
            string name = _Request.GetString("name", "");
            string json = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRoomsJson(bid, floor, name);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void SelectRoomNoList()
        {
            int bid = _Request.GetInt("bid", 0);
            string json = ZLDC.Topo.BLL.Estate.RoomNoBLL.SelectRoomNoList(1, 0, 0, bid);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

    }
}
